actions-on-google 建置 Google Home App #22 notifications 主動推播
雖然document還是寫notification,不過在actions on google 的sdk裡,是用update 這個來實notification 的。
參考
Push notifications | Actions on Google | Google Developers
In this guide, we use the Actions on Google tips sample as a reference to show you how to set up push notifications for…developers.google.com
先 git clone https://github.com/actions-on-google/dialogflow-updates-nodejs 這個範例。
Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project. 先到actions on google 新增專案
Click Skip, located on the top right to skip over category selection menu. 點skip 下去
On the left navigation menu under BUILD, click on Actions.
在BUILD欄裡點Actions。
Click on Add Your First Action and choose your app's language(s).
點Add Your First Action
Select Custom intent, click BUILD. This will open a Dialogflow console. Click CREATE.
這時會跳到 Dialogflow console,點CREATE
Click on the gear icon to see the project settings.
點 設定 圖示
Select Export and Import.
選Export and Import
Select Restore from zip. Follow the directions to restore from the AoG-Tips.zip
file in this repo.
選Restore from zip
Go to the Google Cloud Platform console to activate the Actions API, and select the project that you have created on the Actions on Google console. Then, click the Enable button.
到GCP找 Actions API 並Enable 這個權限。 //這裡我在操作時,找不到我在action on google 所開的專案,如果你跟我一樣遇到這個問題,你可以到action on google的專案設定裡找 projectID,然後再GCP的console上面收尋,就可以找到你開的專案了。
Go to the Firebase console and select the project that you have created on the Actions on Google console.
到Firebase console並且尋找你新增在Actions on Google console的專案;一樣我在這裡一開始也是沒看到我新增專案,我後來在 Dialogflow的fulfilment裡新增inline editor並且在deploy,這個會自動幫你新增firebase function 出來,然後下面有open firebase dashboard,點擊後,就會找到這個專案的firebase了。
Click the gear icon, then select Project settings > SERVICE ACCOUNTS.
點 設定 圖示,選SERVICE ACCOUNTS
Generate a new private key and save it in the functions
folder calling the file service-account.json
.
點Generate a new private key,會下載一個key.json,存到剛剛git clone下來的範例裡的funcitons資料夾。
On the left navigation menu under DEVELOP, click on Database.
點左欄DEVELOP下有個 Database.
Under Cloud Firebase Beta, click Get Started.
在 Cloud Firebase Beta點 Get Started.
Select Start in test mode, click Enable.
選 Start in test mode點Enable
In the functions
directory, deploy the fulfillment webhook provided in the functions folder using Google Cloud Functions for Firebase:
Follow the instructions to set up and initialize Firebase SDK for Cloud Functions. Make sure to select the project that you have previously generated in the Actions on Google Console and to reply N
when asked to overwrite existing files by the Firebase CLI.
在剛剛你git clone下來的範例裡,用terminal下 firebase init ,沒安裝firebase tool,麻煩自已去安裝,記得選你的firebase name。
Run npm install
to install dependencies.
下npm install
Run firebase deploy
and take note of the endpoint where the fulfillment webhook has been published. It should look like Function URL (aogTips): https://${REGION}-${PROJECT}.cloudfunctions.net/aogTips
下firebase deploy
Go back to the Dialogflow console and select Fulfillment from the left navigation menu. Enable Webhook, set the value of URL to the Function URL
from the previous step, then click Save.
會產生兩個網址,將 https://us-central1-push-xxxxx.cloudfunctions.net/aogTips 填到dialogflow的webh
To add tips to the newly created Firestore database, load in a browser https://${REGION}-${PROJECT}.cloudfunctions.net/restoreTipsDB
.
將這個開啟 https://us-central1-push-xxx.cloudfunctions.net/restoreTipsDB 這個會將tipsDB.json的資料倒到firebase database 裡。我一開始沒注意到這個,後面就一直跳錯。
Go to the Actions on Google console.
開啟Actions on Google console
Follow the Console Setup instructions in the Daily Updates and the Push Notifications documentation to enable daily updates and push notifications.
將Daily Updates和 push notifications的設定開啟
後面就照走,測試一下囉
Type Talk to my test app
in the simulator, or say OK Google, talk to my test app
to any Actions on Google enabled device signed into your developer account.
To test daily updates, choose a category. After the tip, the app will show a suggestion chip to subscribe for daily updates.
To test push notifications, choose to hear the latest tip. After the top, the app will show
a suggestion chip to subscribe for push notifications. Add a new tip to the Firestore DB to trigger a notification to the subscribed users.
For more detailed information on deployment, see the documentation.